﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.System.Servers
{
    public class SealServers
    {
	    private readonly IRepository<seal> sealRepository;

        public SealServers()
        {
            sealRepository = new DapperRepository<seal>();

        }

        public List<seal> GetData(string SEAL_ID, string SEAL_NAME)
        {
            var datas = sealRepository.GetAllEnumerable();

            if (!string.IsNullOrEmpty(SEAL_ID))
            {
                datas = datas.Where(m => m.SEAL_ID.Contains(SEAL_ID));
            }
            if (!string.IsNullOrEmpty(SEAL_NAME))
            {
                datas = datas.Where(m => m.SEAL_NAME.Contains(SEAL_NAME));
            }
            return datas.ToList();
        }

        public seal GetModelById(string id)
        {
            return sealRepository.GetById(id);
        }

		
        internal void Add(seal model)
        {
            sealRepository.Insert(model);
        }

        internal void Update(seal model)
        {
            sealRepository.Update(model);
        }

		internal void Del(string id)
        {
            sealRepository.DeleteByIds(id);
        }

				      
        internal List<SelectListItem> GetDEPT_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = sealRepository.SqlWithParamsDynamic("select DEPT_ID Value,DEPT_NAME Text from [dbo].[department]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }
        public string GetDEPT_IDName(string id)
        {
            string DEPT_NAME = string.Empty;
            var DEPT = sealRepository.SqlWithParamsDynamic("select DEPT_NAME from [dbo].[department] where DEPT_ID = @DEPT_ID", new { DEPT_ID = id });
            foreach (var name in DEPT)
            {
                DEPT_NAME = name.DEPT_NAME.ToString().Trim();
            }
            return DEPT_NAME;
        }

    }
}